﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NullObjectStudy
{
    /// <summary>
    /// 通过泛型实现的单例模式
    /// </summary>
    /// <typeparam name="T">具体要实现单例的类型</typeparam>
    public static class Singleton<T> where T : new()
    {
        private static T single;

        public static T Instance 
        {
            get
            {
                if (single == null)
                {
                    single = new T();
                }

                return single;
            }
        }
    }
}
